package com.qdlc.p2p.dal.dao.impl;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.qdlc.p2p.dal.common.dao.jpa.BaseDaoImpl;
import com.qdlc.p2p.dal.dao.UseRateLogDao;
import com.qdlc.p2p.dal.dto.UseRateLog;

/**
 * 用户加息券使用记录DAO接口
 * @author wj
 * @version 2.0
 * @since 2015-04-22
 */
@Repository("useRateLogDao")
public class UseRateLogDaoImpl extends BaseDaoImpl<UseRateLog> implements UseRateLogDao {

    @SuppressWarnings("unchecked")
    @Override
    public UseRateLog getUseRateLogById(long id) {
        String jpql = "from UseRateLog where id = ?1";
        Query query = em.createQuery(jpql);
        query.setParameter(1, id);
        List<UseRateLog> list = query.getResultList();
        if (list != null && list.size() >= 0) {
            return (UseRateLog) list.get(0);
        } else {
            return null;
        }
    }

	@SuppressWarnings("unchecked")
	@Override
	public List<UseRateLog> getUseRateLogByBorrowId(long borrowId) {
		String jpql = "from UseRateLog where borrowId = ?1";
		  Query query = em.createQuery(jpql);
        query.setParameter(1, borrowId);
        List<UseRateLog> list = query.getResultList();
        return list;
	}

	@SuppressWarnings("rawtypes")
	@Override
	public UseRateLog getRateLogByTenderId(long tenderId) {
		String jpql = "from UseRateLog where tenderId = ?1";
		Query query  = em.createQuery(jpql);
		query.setParameter(1, tenderId);
		List list = query.getResultList();
		if (null !=list && list.size()>0) {
			return (UseRateLog)list.get(0);
		}
		return null;
	}
	
	
    
    
}
